package cn.com.scitc.test01.login;


import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.springframework.ui.Model;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class LoginInterceptor implements HandlerInterceptor{

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String reqURI = request.getRequestURI();

//        登录检查逻辑
        HttpSession session = request.getSession();
        Object loginUser = session.getAttribute("user");


        if (loginUser != null){
//            已登录，放行
            return true;
        }

//        拦截未登录，逮回去;
        request.setAttribute("msg","请先登录");
        response.sendRedirect("/login");
        return false;
    }
}
